#include "mouseevent.h"
#include <QStatusBar>
#include <QMouseEvent>
MouseEvent::MouseEvent(QWidget *parent)
    : QMainWindow(parent)
{
    setWindowTitle(tr(" 鼠标事件"));
    statusLabel = new QLabel;
    statusLabel->setText( ("当前位置： ")) ;
    statusLabel->setFixedWidth(100);
    MousePosLabel = new QLabel;
    MousePosLabel->setText(tr(""));
    MousePosLabel->setFixedWidth(100);
    statusBar()->addPermanentWidget(statusLabel);
    statusBar()->addPermanentWidget(MousePosLabel);
    this->setMouseTracking (true);
    resize(400,200);
}

MouseEvent::~MouseEvent()
{
}

void MouseEvent::mousePressEvent(QMouseEvent *event)
{
    QString str=" ("+QString::number(event->x ()) +", "+QString::number (event->y ()) +")";
    if(event->button()==Qt::LeftButton)
    {
        statusBar() ->showMessage(tr("左键:")+str);
    }
    else if (event->button () ==Qt::RightButton)
    {
        statusBar()->showMessage(tr("右键:")+str);
    }
    else if (event->button ()==Qt::MiddleButton)
    {
        statusBar()->showMessage(tr("中键:") +str);
    }
}

void MouseEvent::mouseReleaseEvent(QMouseEvent *event)
{
    QString str=" ("+QString::number(event->x ()) +", "+QString::number (event->y ()) +")";
    statusBar() ->showMessage(tr("释放在:")+str);
}

void MouseEvent::mouseDoubleClickEvent(QMouseEvent *event)
{
    
}

void MouseEvent::mouseMoveEvent(QMouseEvent *event)
{
    MousePosLabel->setText (" ("+QString::number(event->x())+", "+QString::number(event->y())+") ");
}

